<?php header("content-Type: text/html; charset=UTF-8");
date_default_timezone_set("PRC");

	//数据库链接文件
	include('../api/conn.php');  


	if( isset($_REQUEST['userid']))
		$user_id = $_REQUEST['userid'];
	else
		$user_id = "";

	$amount=0;
	if(isset($_REQUEST['amount']))
		$amount=$_REQUEST['amount'];
	
	$paytypeid=1;
	if(isset($_POST['payType']))
		$paytypeid=$_POST['payType'];

	// check the userid
	$order_no = date('YmdHis') . mt_rand(10000, 99999);
	$order_time =date("Y-m-d H:i:s",time());
	$order_amount = $amount;
	
	$sql="select * from t_user where t_id=$user_id";
	$query=sqlsrv_query($conn,$sql);
	$result=sqlsrv_fetch_array($query,SQLSRV_FETCH_NUMERIC);
	if(empty($result))
	{
		exit("用户ID 不存在");
	}
	//check the ordernumber
	$sql="select * from t_chongzhi_log where order_no='$order_no' and t_user_id=$user_id";
	
	$query=sqlsrv_query($conn,$sql);
	$result=sqlsrv_fetch_array($query,SQLSRV_FETCH_NUMERIC);
	if(empty($result)){
		$content = iconv("utf-8","gb2312//IGNORE","在线充值");
		$sql="insert into t_chongzhi_log (t_user_id,t_jine,t_time,t_state,t_pingtai,t_tishi,order_no,attach,comments) 
				values ($user_id,$order_amount,'$order_time',0, '$content',0, '$order_no', 'transfer_bank','')";
	//			echo $sql;
		$query=sqlsrv_query($conn,$sql);		
		//print_r(sqlsrv_errors());
		//exit;
	}

	
//执行数据库脚本2
	if($paytypeid == 2)		//支付宝
	{
		$sql_payinfo =  "SELECT TOP 1 [t_type], [t_yinhang]
		  ,[t_kaihuren]
		  ,[t_zhanghao]
		  ,[t_web]
		  ,[t_kaihuren1]
		  ,[t_zhanghao1]
		  ,[t_web1]
		  FROM [LuckMeDB].[dbo].[t_chongzhi]
		where comments='BankDirect'";
	}
	else
	{
		$sql_payinfo =  "SELECT TOP 1 [t_type], [t_yinhang]
		  ,[t_kaihuren]
		  ,[t_zhanghao]
		  ,[t_web]
		  ,[t_kaihuren1]
		  ,[t_zhanghao1]
		  ,[t_web1]
		  FROM [LuckMeDB].[dbo].[t_chongzhi]
		where comments='WxBank'";
		
	}
//	echo $sql_payinfo;
	$user_query2 = sqlsrv_query($conn, $sql_payinfo);
    
	if(empty($user_query2))
	{
		exit(' 遇到数据库错误！请点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');  
	}
	
	$payBankInfo= array();

	$row2 = sqlsrv_fetch_array($user_query2, SQLSRV_FETCH_ASSOC);  
	if(!empty($row2))
	{
		$payBankInfo[0] = $row2['t_yinhang'];
		$payBankInfo[1] = $row2['t_kaihuren'];
		$payBankInfo[2] = $row2['t_zhanghao'];
		$payBankInfo[3] = $row2['t_web'];		
	}
	else
		echo '获取数据库充值参数出错！';


//	var_dump($payBankInfo);
	$bankname = iconv('GBK','UTF-8', $payBankInfo[0]);
	$AccountName = iconv('GBK','UTF-8', $payBankInfo[1]);
	$AccountNumber= iconv('GBK','UTF-8', $payBankInfo[2]);
	$UserName = iconv('GBK','UTF-8', $payBankInfo[3]);

	//echo $bankname;
?>
	


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head id="Head1">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>
			充值中心
		</title>
	<link href="./css/Main.css" rel="stylesheet">
	<link href="./css/cz.css" rel="stylesheet">
	<link href="./css/style.css" rel="stylesheet">
    <script type="text/javascript" src="./js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="./js/jquery.zclip.js"></script>
    <style type="text/css">
        #tbBankList img {
            cursor: pointer;
        }
        /* 复制提示 */ .copy-tips {
            position: fixed;
            z-index: 999;
            bottom: 50%;
            left: 50%;
            margin: 0 0 -20px -80px;
            background-color: rgba(0, 0, 0, 0.2);
            filter: progid:DXImageTransform.Microsoft.Gradient(startColorstr=#30000000, endColorstr=#30000000);
            padding: 6px;
        }

        .copy-tips-wrap {
            padding: 10px 20px;
            text-align: center;
            border: 1px solid #F4D9A6;
            background-color: #FFFDEE;
            font-size: 14px;
        }
    </style>
</head>
<body>
    
	<div id="cz_header">
    <div class="cz_header">
        <div class="cz_logo"></div>
        <div id="cz_bg_div" class="cz_nav" style="display:none">
            <ul class="clearfix">
                <li><a href="javascript:void(0); changePayType(0, '在线充值')">在线充值</a></li>
                <li><a href="javascript:void(0); changePayType(1, '支付宝')">支付宝充值</a></li>
                <li><a href="javascript:void(0); changePayType(2, '微信')">微信充值</a></li>
                <li><a href="javascript:void(0); changePayType(3, 'QQ充值')">QQ充值</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="cztd-wrap">
    <ul class="cztd" id="childNav">
    </ul>
</div>
<script type="text/javascript">
    var Global_HeaderJson =	[{"ID":245,"BankUrl":"http://www.username=","PayClass":4,"TranferUrl":null,"ShowTitle":"支付宝充值16","PayMinMoney":50,"PayMaxMoney":5000,"ShowType":2},{"ID":205,"BankUrl":"http://www.com/ZFBSM/default.aspx?bt=2&IndexId=205&username=","PayClass":4,"TranferUrl":null,"ShowTitle":"支付宝(手机电脑)","PayMinMoney":500,"PayMaxMoney":10000,"ShowType":2},{"ID":231,"BankUrl":"http://www.com/SHSM/default.aspx?bt=7&IndexId=231&username=","PayClass":4,"TranferUrl":null,"ShowTitle":"大额支付宝1","PayMinMoney":5000,"PayMaxMoney":50000,"ShowType":2},{"ID":233,"BankUrl":"http://www.com/SHSM/default.aspx?bt=5&IndexId=233&username=","PayClass":7,"TranferUrl":null,"ShowTitle":"银联扫码2","PayMinMoney":100,"PayMaxMoney":4000,"ShowType":0},{"ID":239,"BankUrl":"http://www.com/TFSM/default.aspx?IndexId=239&username=","PayClass":2,"TranferUrl":null,"ShowTitle":"微信充值2","PayMinMoney":50,"PayMaxMoney":500,"ShowType":2},{"ID":188,"BankUrl":"http://www.com/KJSM/default.aspx?bt=2&IndexId=188&username=","PayClass":4,"TranferUrl":null,"ShowTitle":"支付宝充值1","PayMinMoney":5000,"PayMaxMoney":50000,"ShowType":2},{"ID":191,"BankUrl":"http://www.com/KJWYSM/default.aspx?bt=5&IndexId=191&username=","PayClass":7,"TranferUrl":null,"ShowTitle":"银联扫码","PayMinMoney":50,"PayMaxMoney":4500,"ShowType":0}];
    var Global_IndexId = 255;
    var Global_UserID ='';
    var Global_Type ='';
    var transferUrl;
    var Chk='';
    var payMinMoney=50;
    var payMaxMoney=500;
    var isPc = 'True'

    function useMobileFun() {
        $(".cz_nav").hide()
        $("head").append('<meta name="viewport" content="width=device-width, initial-scale=1,  user-scalable=no" />');
        $("head").append('<link href="/css/Stitics/czmobile.css" rel="stylesheet" />')
    }
    
    function createShowRange(){
        document.write( "<span>充值范围："+payMinMoney+"元->"+payMaxMoney+"元</span>");
    }
    if(Chk=='1')
    {
        payMaxMoney=100000;
    }
    document.oncontextmenu = function () { return false; }
    $(function () {
        $(".cz_nav ul li").click(function () {
            var $t = $(this);
            var pType = $t.find("a").attr('paytype');
            //if(pType.indexOf(Global_Type)>-1){
            //    return;
            //}            
            var temp = [];
            $.each(Global_HeaderJson, function (ind, content) {
                if (pType.indexOf(content.PayClass) > -1) {
                    temp.push(content);
                }
            });

            $.each(temp, function (ind, content) {
                if (ind == 0) {
                    transferUrl =$.trim( content.BankUrl )+$.trim(  Global_UserID);
                }
            });
            if(typeof(transferUrl)!='undefined')
                window.location.href = transferUrl;
        });

        if (isPc != "True") {
            useMobileFun();
        }
    });

    function checkUser(userName){
        if(userName.indexOf('=')>-1){
            return false;
        }
        var data= "userName="+userName;
        var flag=false;
        $.ajax({
            type: "POST",
            url: "/Common/Pages/CommonPage.ashx?method=checkUser",
            data:data,
            async: false,
            success: function(r){
                var json = eval("("+r+")")
                flag = (json.result=="1");
            }
        });
        return flag;
    }
</script>


    <form name="mainForm" method="post" action="#" id="mainForm">

        <div class="cz_box">
            <div class="cz_step">
                <ul class="clearfix">
                    <li><font>1</font>.填写金额</li>
                    <li class="cz_arrow"><font>2</font>.确定充值信息</li>
                    <li class="cz_arrow"><font>3</font>.登陆支付宝</li>
                </ul>
            </div>
            <div class="cz_box1">
                <div class="cz_box_tit">
                    充值确定
                </div>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                        <tr>
                            <td class="td1">充值方式：
                            </td>
                            <td class="td2">
                                <img id="paytype_idsrc" src="./Images/ALIPAYWAP.jpg">
                            </td>
                            <td class="td3" rowspan="4">
<?php if($paytypeid == 2)
	{
?>							
                                <a href="https://www.alipay.com/" target="_blank">
                                    <input id="login_bank" type="button" value="登录支付宝" class="inputzfb">
                                </a>
<?php
	}
	else
	{
?>
                                <a href="https://wx.qq.com/" target="_blank">
                                    <input id="login_bank" type="button" value="登录微信" class="inputwx">
                                </a>

<?php }
?>
						<input type="submit" name="btnCheDan" value="" id="btnCheDan" class="inputcd">
                            </td>
                        </tr>
                        <tr>
                            <td class="td1">充值ID：
                            </td>
                            <td class="td2">
                                <?php echo $user_id?>
                            </td>
                        </tr>
                        <tr>
                            <td class="td1">充值金额：<input name="hidName" type="hidden" id="hidName" value="kai888">
                            </td>
                            <td class="td2">
                                <font color="#FF0000" size="+1"> <?php echo $amount;?></font>元
                            </td>
                        </tr>
                        <tr>
                            <td class="td1"></td>
                            <td class="td2">请您尽快完成充值
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <font color="#FF0000"></font>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="clearfix">
                <div class="cz_box2">
                    <div class="cz_box_tit">
                        详细信息
                    </div>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <td class="td1">收款银行：
                                </td>
                                <td class="td2">
                                    <span><?php echo $bankname; ?></span>
                                </td>
                                <td class="td3">
                                    <input type="text" title="复制" value="复制" class="spnCopy">
								</td>
                            </tr>
                            <tr>
                                <td class="td1">收款人姓名：
                                </td>
                                <td class="td2">
                                    <span><?php echo $AccountName; ?> </span>
                                </td>
                                <td class="td3">
                                    <input type="text" title="复制" value="复制" class="spnCopy">
								</td>
                            </tr>
                            <tr>
                                <td class="td1">收款人账号：
                                </td>
                                <td class="td2">
                                    <span><?php echo $AccountNumber;?> </span>
                                </td>
                                <td class="td3">
                                    <input type="text" title="复制" value="复制" class="spnCopy">
								</td>
                            </tr>
                            <tr>
                                <td class="td1">附言：
                                </td>
                                <td class="td2">
                                    <span><?php echo $amount .".". rand(00,99) ?></span>
                                </td>
                                <td class="td3">
                                    <input type="text" title="复制" value="复制" class="spnCopy">
                                <div class="zclip" id="zclip-ZeroClipboardMovie_4" style="position: relative; top: -20px; width: 68px; height: 27px; z-index: 99; float: left;">
									<embed id="ZeroClipboardMovie_4" src="./js/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="68" height="27" name="ZeroClipboardMovie_4" align="middle" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&amp;width=68&amp;height=27" wmode="transparent">
								</div></td>
                            </tr>

                            <tr>
                                <td class="td1">注意事项：
                                </td>
                                <td class="td2" colspan="2">
                                    <span class="fb">充值金额必须按附言金额充值，附言码为随机生成，一个附言只能充值一次 </span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="cz_box3">
                    <div class="cz_box_tit">
						充值有效时间：
                    </div>
                    <div class="time">
                        <span id="t_h">00</span>:<span id="t_m">29</span>:<span id="t_s">15</span>
                    </div>
                    <div class="time_txt">
                        为保障充值成功请在 <font color="#FF0000">30分钟</font>内完成充值
                    </div>
                </div>
            </div>
            <div class="cz_ts">
                <dl>
                    <dt>充值说明： </dt>
                    <dd>
                        <p>
                            1.务必填写附言，附言码为随机生成，一个附言只能充值一次,并且充值金额必须相同，过期或者重复使用充值将无法到账
                        </p>
                    </dd>
                    <dd>
                        <p>
                            2.收款账户名和账户号不定期更换，请在获取最新信息后充值，否则充值无法到账
                        </p>
                    </dd>

                </dl>
            </div>
        </div>
        <input name="hidUserID" type="hidden" id="hidUserID" value="<?php echo $user_id?>">
        <input name="hidMoney" type="hidden" id="hidMoney" value="<?php echo $amount;?>">
    </form>
    <script type="text/javascript">
        $(document).ready(function () {
            /* 定义所有class为copy-input标签，点击后可复制class为input的文本 */
            $(".spnCopy").zclip({
                path: "/js/ZeroClipboard.swf",
                copy: function () {
                    return $.trim($(this).parent().parent().find("span").html());
                },
                afterCopy: function () {/* 复制成功后的操作 */
                    var $copysuc = $("<div class='copy-tips'><div class='copy-tips-wrap'>☺ 复制成功</div></div>");
                    $("body").find(".copy-tips").remove().end().append($copysuc);
                    $(".copy-tips").fadeOut(3000);
                }
            });
            $(".zclip").css("float", "left");
        });
    </script>
    <script type="text/javascript">
        var h = _$('t_h'),
            m = _$('t_m'),
            s = _$('t_s'),
            sto = null;

        var now = new Date();
        var start = new Date();
		start.setMinutes (start.getMinutes() + 30);

        function _$(id) {
            return document.getElementById(id);
        }
        //start eg: 2014-12-1 12:00:00
        function getSeconds(start, now) {
            var d = (new Date(start)).getTime() - (new Date(now)).getTime();
            return d > 0 ? d : 0;
        }

        function run() {
            var sec = getSeconds(start, now) / 1000,
                d = parseInt(sec / (60 * 60 * 24), 10),
                h = parseInt((sec / (60 * 60) - d * 24), 10),
                m = parseInt(sec / 60 - d * 24 * 60 - h * 60),
                s = parseInt(sec - d * 24 * 60 * 60 - h * 60 * 60 - m * 60),
                timer = {
                    d: d,
                    h: h,
                    m: m,
                    s: s
                };

            toHTML(timer);

            sto = setInterval(function () {
                timer = mulit(timer);

                if (timer.d === -1) {
                    alert('支付时间已到!');
                    window.location.href = 'paybank.php?userid=<?php echo $user_id?>&paytype=4';
                    clearInterval(sto);
                } else {
                    toHTML(timer);
                }
            }, 1000);
        }
        function mulit(timer) {
            var t = timer,
                d = t.d,
                h = t.h,
                m = t.m,
                s = t.s;
            if (s > 0) {
                s -= 1;
            } else {
                m -= 1;
                s = 59;
            }
            if (m < 0) {
                h -= 1;
                m = 59;
            }
            if (h < 0) {
                d -= 1;
                h = 23;
            }
            return {
                d: d,
                h: h,
                m: m,
                s: s
            };
        }
        function toHTML(timer) {
            var t = timer;

            var hh = checkTime(t.h);
            var mm = checkTime(t.m);
            var ss = checkTime(t.s);

            //d.innerHTML = t.d;
            h.innerHTML = hh;
            m.innerHTML = mm;
            s.innerHTML = ss;
        }

        function checkTime(i) {
            var ii = parseInt(i);
            if (ii < 10) {
                ii = "0" + ii;
            }
            return ii;
        }
		
	//手机端功能    
    function useMobileFun() {
        $(".cz_nav").hide()
        $("head").append('<meta name="viewport" content="width=device-width, initial-scale=1,  user-scalable=no" />');
        $("head").append('<link href="css/czmobile.css" rel="stylesheet" />')
    }
	
    //切换支付方式
    function	changePayType(payType, strDesc)
    {
    	if(payType == '0')
    	{
    		document.getElementById("cz_bg_div").className="cz_nav bg";
    		onlineBankPay('<?php echo $user_id ?>', '在线网银支付', '网银支付接口');
    	}
		if(payType == '1')
    	{
    		document.getElementById("cz_bg_div").className="cz_nav bg2";
    		qrcodeBank('1','qrcodePay','2','微信支付');		
    	}
		if(payType == '2')
    	{
    		document.getElementById("cz_bg_div").className="cz_nav bg3";
    		qrcodeBank('2','qrcodePay','5','支付宝');		
    	}
		if(payType == '3')
    	{
    		document.getElementById("cz_bg_div").className="cz_nav bg4";
    		qrcodeBank('3','qrcodePay','4','QQ扫码支付');		
    	}	
    		//change the input interface....
		if(payType == '4')
    	{
    		document.getElementById("cz_bg_div").className="cz_nav bg5";
    		qrcodeBank('4','qrcodePay','4','网银转账');		
    	}	

    		
    }  
    run();
	useMobileFun();
	
    </script>


<?php  
	
	
	function	ShowDiv($divName, $isShow)
	{
		if($isShow == "1")
			echo "<script type='text/javascript'> document.getElementById('$divName').style.display='block'; </script>";
		else
			echo "<script type='text/javascript'> document.getElementById('$divName').style.display='none'; </script>";
	
	}
	
	//show pay infomation
	function 	ShowPayInfo($aa, $bb, $cc, $dd, $tid, &$pay_type)
	{
//		echo $aa.$bb.$cc;
//		class='cur'				//selected...

		if( isset($_REQUEST['tid']))
			$st_id = $_REQUEST['tid'];
		else
			$st_id = "";
			

		if($tid == $st_id)
		{
			$pay_type=$dd;
			echo "<script type='text/javascript'> document.getElementById('childNav').innerHTML += \"<li class='cur'> <a href='$cc&paytype=$dd&tid=$tid'>	<img src='$bb'><p>$aa</p> </a>	</li>\" </script>";
		}
		else
			echo "<script type='text/javascript'> document.getElementById('childNav').innerHTML += \"<li> <a href='$cc&paytype=$dd&tid=$tid'>	<img src='$bb'><p>$aa</p> </a>	</li>\" </script>";
										
	}
	
	
	if(1)
	{
			//执行数据库脚本：第一个横向的支付方式的开关
		$user_sql = "exec p_get_chongzhi_xinxi ?,?";  
		$params = array();
		$params[0] = $user_id;
		$params[1] = 0;
		$result=sqlsrv_query($conn,$user_sql,$params);

		if(empty($result))
		{
			exit(' 遇到数据库错误！请点击此处 <a href="javascript:history.back(-1);">返回</a> 重试');  
		}
	

		while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
		{
			$a_id		= $row['t_type'];
			$a_yinhang 	= iconv("gb2312", "utf-8", $row['t_yinhang'] );
			$a_url	 	= $row['t_web'] . '?userid=' . $user_id;

			$img_name="";
			$tmp_pay_type='';
			if(strstr($a_yinhang, "支付宝") )
			{
				$img_name="Images/paybtn3.PNG";	
				$tmp_pay_type='2';
			}
			else	if(strstr($a_yinhang, "微信"))
			{
				$img_name="Images/WEIXINWAP.png";	
				$tmp_pay_type='1';
			}
			else if(strstr($a_yinhang, "QQ"))
			{
				$img_name="Images/QQWAP.png";	
				$tmp_pay_type='3';
			}
			else
			{
				$img_name="Images/paybtn0.png";	
				$tmp_pay_type='0';		
			}
			ShowPayInfo($a_yinhang, $img_name, $a_url, $tmp_pay_type, $a_id, $g_pay_type);
		}
	
	}

?>


	</body>
	
<script type="text/javascript">
	
	var var_paytypeid = <?php echo $paytypeid;?>;
	if(var_paytypeid == 1)
	{
		document.getElementById("paytype_idsrc").src="./Images/WEIXINWAP.jpg";
	}
    </script>
	
</html>